package cn.ycl.syslog;

import cn.ycl.entity.UserInfoVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;

import java.lang.reflect.Method;

/**
 * @author YuanChangLiang
 * @description
 * @date created in 8:53 2021/6/4
 */

@Component
@Aspect
@Slf4j
@RequiredArgsConstructor
public class HelloAspect {

    //配置切入点（@annotation代表使用了该注解的都进行切入）
    @Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
    public void getMappingCut(){}

    @Before("getMappingCut()")
    public Object getMappingAspect(JoinPoint joinPoint){
        // 方法签名
        MethodSignature signature = (MethodSignature)joinPoint.getSignature();
        // 获取的是代理类的method对象
        Method method = signature.getMethod();
        String[] parameterNames = signature.getParameterNames();

        PostMapping annotation = method.getAnnotation(PostMapping.class);
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if(arg instanceof UserInfoVO){
                //标识可以收集参数
            }
        }
        return null;
    }
}
